﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Customer.aspx.cs" Inherits="CSPTest.Admin.Customer" %>


<asp:Content  ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
    <link href="../content/entity.css" rel="stylesheet" type="text/css" />

    <style>
        .relative-row { clear: both; }
        .relative-row input { width: 80px; float: left; }
        .relative-row label { float: left; }
        .relative-table { padding: 2px;}
        .relative-delete {     width: 15px;  height: 15px;   float: left;  background-image: url(../../content/images/delete.png); }
    </style>

    <script src="../js/jquery-1.4.4.min.js" type="text/javascript"></script>

    <script src="../js/jquery-ui.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(function () {
            $("input:submit,input:button").button();

            $(".entity-delete a")
                .attr("title", "Delete")
                .bind("click", function () {
                    return confirm("Are you sure to delete this item?");
                });

            $(".entity-modify a")
                .attr("title", "Modify");

            var rmRelative = function (e) {
                e.parent().remove();
            };

            $(".relative-delete")
                .attr("title", "Remove this item")
                .bind("click", function () {
                    rmRelative($(this));
                });

            $(".relative-add")
                .attr("title", "Add a new relative for the current customer")
                .bind("click", function () {

                    $(".relative-table").append("<div class=\"relative-row\"><label for=\"relative-name\">Name: </label><input name=\"relative-name\" /> <label for=\"relative-relationship\">Relationship: </label><input name=\"relative-relationship\" /> <label for=\"relative-job\">Job: </label><input name=\"relative-job\" /> <label for=\"relative-mobile\">Mobile: </label><input name=\"relative-mobile\" /><a class=\"relative-delete\" href=\"javascript:void(0)\"></a></div>");
                    $(".relative-delete").last()
                        .attr("title", "Remove this item")
                        .bind("click", function () {
                            rmRelative($(this));
                        });

                });

        });
    </script>

</asp:Content>
<asp:Content   ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <h1>
            Country Management</h1>
        <asp:TextBox ID="SearchText" runat="server"></asp:TextBox>
        <asp:Button  runat="server" ToolTip="Search by the keywords" Text="Search" />
        <asp:Button runat="server" ToolTip="Clear all the search keywords" Text="Clear" ID="BtnClear" />
        
        <asp:GridView ID="gvMain" runat="server" AutoGenerateColumns="False" DataKeyNames="CustomerID"
            DataSourceID="edsMain" AllowPaging="True" AllowSorting="True" EmptyDataText="没有数据">
            <Columns>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
              
              
                <asp:TemplateField HeaderText="Relatives">
                    <ItemTemplate>
                        <asp:Repeater runat="server" DataSource='<%#GetRelatives(EvalX("Relatives")) %>'>
                            <ItemTemplate>
                                <%#Eval("Name") %> (<%#Eval("Relationship") %>),
                            </ItemTemplate>
                        </asp:Repeater>
                    </ItemTemplate>
                </asp:TemplateField>
              
           
                
                
                <asp:ButtonField CommandName="Modify" ButtonType="Link" ItemStyle-CssClass="entity-modify" />
                <asp:ButtonField CommandName="Disable" ButtonType="Link" ItemStyle-CssClass="entity-delete" />
            </Columns>
        </asp:GridView>
        <asp:Button ID="BtnAdd" runat="server" Text="Add" />
        <asp:DetailsView ID="dvMain" runat="server" AutoGenerateRows="False" DataKeyNames="CustomerID"
            DataSourceID="edsMain">
            <Fields>
                <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

                  <%--家属--%>
                <asp:TemplateField HeaderText="Relatives">
                    <EditItemTemplate>
                        <div class="relative-table">
                                                           
                        <asp:Repeater runat="server" DataSource='<%# GetRelatives(EvalX("Relatives")) %>'>
                            <ItemTemplate>
                                <div class="relative-row">
                                    <label for="relative-name">
                                        Name:
                                    </label>
                                    <input name="relative-name" value="<%#Eval("Name") %>" /><label for="relative-relationship">Relationship:
                                    </label>
                                    <input name="relative-relationship" value="<%#Eval("Relationship") %>" /><label for="relative-job">Job:
                                    </label>
                                    <input name="relative-job" value="<%#Eval("Job") %>" /><label for="relative-mobile">Mobile:
                                    </label>
                                    <input name="relative-mobile" value="<%#Eval("Mobile") %>" /><a class="relative-delete"
                                        href="javascript:void(0)"></a></div>
                            </ItemTemplate>
                        </asp:Repeater>

                        </div>
                        <br style="clear: both;" />
                        <a href="javascript:void(0)" class="relative-add">Add</a>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <div class="relative-table">
                        </div>
                        <br style="clear: both;" />
                        <a href="javascript:void(0)" class="relative-add">Add</a>
                    </InsertItemTemplate>
                </asp:TemplateField>

                <asp:CommandField ShowEditButton="True" ShowInsertButton="True" ButtonType="Button" />
            </Fields>
        </asp:DetailsView>
        
        <%--以下是数据源--%>
        <asp:EntityDataSource ID="edsMain" runat="server" ConnectionString="name=CSPEntities"
            DefaultContainerName="CSPEntities" EnableInsert="True" EnableUpdate="True" EntitySetName="Customers"
            Include="Relatives" Where="!it.Disabled">
        </asp:EntityDataSource>
          
    </div>
</asp:Content>
